#include "dxyevent.h"


namespace dxy::event
{


DxyEvent::DxyEvent()
{
    m_epollfd = epoll_create(1024);
    if(m_epollfd == -1) throw std::exception();
}

DxyEvent::~DxyEvent()
{

}

void DxyEvent::delEvent(int fd)
{
    epoll_ctl(m_epollfd, EPOLL_CTL_DEL, fd, nullptr);
}

void DxyEvent::eventDispatch()
{
    while(1)
    {
        int evNum = epoll_wait(m_epollfd, m_events, 1024, -1);
        for(int i = 0; i < evNum; i++)
        {
            m_eventsCbs[m_events[i].data.fd]();
        }
    }
}




}